package com.rrjjg.generate;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * ----------------------------------------------------------------------------- <br>
 * 功能 :  <br>
 * ----------------------------------------------------------------------------- <br>
 * 作者 : Vayne <br>
 * 时间 : 2022/7/6 9:06 <br>
 */
@Mojo(name = "mybatis-plus-generate")
public class GenerateMojo extends AbstractMojo {

    @Parameter(name = "url", defaultValue = "jdbc:oracle:thin:@192.168.104.54:1521:kcpt")
    private String url;
    @Parameter(name = "user", defaultValue = "kcpt")
    private String user;
    @Parameter(name = "password", defaultValue = "kcpt")
    private String password;
    @Parameter(name = "pack", defaultValue = "com.sinoiov.hypt")
    private String pack;
    @Parameter(name = "module", defaultValue = "hyjg")
    private String module;
    @Parameter(name = "tables", required = true)
    private String tables;
    @Parameter(name = "prefix", defaultValue = "TB_,TH_,TS_")
    private String prefix;
    @Parameter(name = "author", defaultValue = "Vayne")
    private String author;
    @Parameter(name = "driver", defaultValue = "oracle")
    private String driver;


    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        DBConfig dbConfig = new DBConfig();
        dbConfig.setAuthor(author)
                .setDbUrl(url)
                .setUserName(user)
                .setPassword(password)
                .setPack(pack)
                .setModuleName(module)
                .setTables(tables)
                .setDbType(driver)
                .setTbPrefix(prefix);
        new MyBatisGenerator(dbConfig).generator();
    }
}
